using Core.Contracts.Interfaces;

namespace Core.Features
{
    using System;
    using Base;
    using Contracts.Enums;
    using Resources;
    using Core.Contracts.Interfaces;
    using System.Linq;

    
    public sealed class SeismicEHP<T> : FeatureBase<object>
    {
        public SeismicEHP(){}

        public SeismicEHP(T value) 
            : base(value){ }
        /// <summary>
        /// Obtains the feature name
        /// </summary>
        public override string Name
        {
            get { return "Seismic EHP"; }
        }
        /// <summary>
        /// Obtains the feature group
        /// </summary>
        public override FeatureGroupsEnum FeatureGroup{ get { return FeatureGroupsEnum.Defence; } }
        /// <summary>
        /// Obtains the feature type
        /// </summary>
        public override FeaturesEnum FeatureType { get { return FeaturesEnum.SeismicEHP; } }
        /// <summary>
        /// Obtains or defines the feature unit
        /// </summary>
        public override string Unit { get { return Traduction.label_unit_hp; } }

        public override void SetModifiedValue(IAgent agent, IRobot robot)
        {
            if (agent == null || robot == null) return;

            // Chemical Resist
            var Resist = robot.Features.Where(f => f.FeatureType == FeaturesEnum.SeismicResistance).FirstOrDefault().IsModified
               ? (double)robot.Features.Where(f => f.FeatureType == FeaturesEnum.SeismicResistance).FirstOrDefault().ModifiedValue
                       : (double)robot.Features.Where(f => f.FeatureType == FeaturesEnum.SeismicResistance).FirstOrDefault().Value;

            // Armor Amount
            var armorAmt = robot.Features.Where(f => f.FeatureType == FeaturesEnum.ArmorAmount).FirstOrDefault().IsModified
               ? (double)robot.Features.Where(f => f.FeatureType == FeaturesEnum.ArmorAmount).FirstOrDefault().ModifiedValue
                       : (double)robot.Features.Where(f => f.FeatureType == FeaturesEnum.ArmorAmount).FirstOrDefault().Value;

            double temp = armorAmt / (1 - (Resist / 100));

            ModifiedValue = IsRounded
                                ? Math.Round(temp, 0, MidpointRounding.AwayFromZero)
                                : Math.Round(temp, 0);
        }
    }
}